home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 6 / CU Amiga Magazine's Super CD-ROM 06 (1996)(EMAP Images)(GB)(Track 1 of 4)[!][issue 1997-01].iso / cucd / readers / games / sfx2worms / sfx2worms.c < prev   
C/C++ Source or Header  |  1996-05-19  |  3KB  |  112 lines

  1.  
  2. /* This program converts PC Worms Reinforcements samplefile
  3.    to Amiga IFF separate files. 
  4.  
  5.  Compiler used: SAS/C 6.51
  6.  
  7.  You must have MCConstants enabled in scoptions!
  8.  
  9. */
  10.  
  11. #include <stdio.h>
  12.  
  13. #define MAXSIZE 100000
  14.  
  15. int start[256],len[256];
  16.  
  17. char *sname[69] = { "Revenge", "OhDear", "OiNutter", "Oooff1", "Oooff2", "Oooff3",
  18.     "Oooww1", "Oooww2", "Oooww3", "Perfect", "Pop", "Punch", "Reload", "Shotgun",
  19.     "Splash", "Stupid", "TakeCover", "Baa", "Teleport", "Traitor", "Twang", "Uzi",
  20.     "WatchThis", "WhatThe", "Whoops", "Wobble", "YesSir", "You'llRegretThat", "Hello",
  21.     "Fuse", "Glasses", "Grenade", "Hup1", "Hup2", "Hurry", "I'llGetYou", "JustYouWait",
  22.     "Kamikaze", "Laugh", "LeaveMeAlone", "Mine",    "Missed", "Nooooo", "Bazooka",
  23.     "BlowTorch", "Boring", "Bungee", "ByeBye", "ComeOnThen", "Communicator", "Coward",
  24.     "Die", "DragonPunch", "Drill", "Excellent", "Explosion", "ExplosionUW", "Fatality",
  25.     "Fire", "FireBall", "FirstBlood", "Flawless", "MiniGun", NULL, NULL, NULL,
  26.     "AirStrike", NULL, NULL };
  27.  
  28. int iffhdr[] = { 'FORM', 0, '8SVX', 'VHDR', 0x14, 0, 0, 0, 0x3a980100, 0xffff,
  29.         'NAME', 0x14, 'Just', ' a s', 'ampl', 'e!\0\0', 0, 
  30.         'ANNO', 0x14, 'sfxd', '2wor', 'ms\0\0', 0, 0, 'BODY', 0 };
  31.  
  32. far char sbuf[MAXSIZE];    /* sample buffer */
  33.  
  34. /* function that converts Intel integers to Motorola format */
  35. int pctoamy(int val)
  36. {
  37.     int res;
  38.     
  39.     res =(val>>24)& 0x000000ff;
  40.     res|=(val>>8) & 0x0000ff00;
  41.     res|=(val<<8) & 0x00ff0000;
  42.     res|=(val<<24)& 0xff000000;
  43.     
  44.     return res;
  45. }
  46.  
  47. /* main */
  48. int main (char **argv,int argc)
  49. {
  50.     int x;
  51.     FILE *in,*out;
  52.     
  53.     printf("SFX to Amiga Worms converter\nVersion 1.0\nAuthor: Teemu Suikki <zuikkis@sci.fi>\n\n");
  54.     
  55.     if (argc!=2) {
  56.         printf("Usage: sfx2worms <filename>\n");
  57.         return 10;
  58.     }
  59.     
  60.     if (!(in=fopen(argv[1],"rb"))) {
  61.         printf("Input file '%s' not found!\n",argv[1]);
  62.         return 10;
  63.     }
  64.     
  65.     printf("Reading file '%s'\n",argv[1]);
  66.     
  67. /* read sample start and stop addresses */    
  68.     fread(start,4,256,in);
  69.     fread(len,4,256,in);
  70.     
  71. /* convert those ugly PC-integers to understandable numbers, calculate len */
  72.     for (x=0;x<256;x++) {
  73.         start[x]=pctoamy(start[x]);
  74.         len[x]=pctoamy(len[x])-start[x];
  75.     }    
  76.     
  77. /* fix pointers for samples 62-65 */    
  78.     start[62]=start[21];len[62]=len[21];    /* Minigun     -> Uzi         */
  79.  
  80. /* read samples and write output */    
  81.     for (x=0;x<69;x++) {
  82.         if (sname[x]) {
  83.  
  84.             if (len[x]>MAXSIZE) {
  85.                 printf("Sample #%d (%s) too long! Truncated.\n",x,sname[x]);
  86.                 len[x]=MAXSIZE;
  87.             }
  88.             
  89.             fseek(in,start[x]+0x800,SEEK_SET);    /* seek correct position */
  90.             fread(sbuf,len[x],1,in);            /* read data */
  91.         
  92.             if (len[x] & 1) len[x]--;            /* must be even length */
  93.         
  94.             iffhdr[1]=len[x]+0x60;                /* fill in IFF header */
  95.             iffhdr[6]=len[x];
  96.             iffhdr[25]=len[x];
  97.         
  98.             if (!(out=fopen(sname[x],"wb"))) {
  99.                 printf("Can't open output file '%s'\n",sname[x]);
  100.                 return 10;
  101.             }
  102.         
  103.             fwrite(iffhdr,4,26,out);        /* write iff header */
  104.             fwrite(sbuf,len[x],1,out);        /* write sample data */
  105.             fclose(out);
  106.         }
  107.         
  108.     }
  109.     fclose(in);
  110.     printf("Done!\n");
  111. }    
  112.